package com.hyts.rxjava.bus.publish;

import com.hyts.rxjava.bus.event.DefaultEvent;
import rx.Observable;
import rx.Scheduler;
import rx.schedulers.Schedulers;

import java.util.List;
import java.util.Optional;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.rxjava.bus.publish
 * author:Libo/Alex
 * create-date:2019-06-27 17:57
 * email:liboware@gmail.com
 * description:此类主要用于: 主要作为对应DefaultEvent事件操作服务对象发布者
 */

public class DefaultEventPublisher extends EventPublisher<DefaultEvent>{



    @Override
    public Observable<DefaultEvent> publish(DefaultEvent subject) {
        if(subject == null){
            throw new NullPointerException("传入的对象subject不可以为空！");
        }
        return Observable.just(subject).subscribeOn(Schedulers.io())/*.observeOn(Schedulers.newThread())*/;
    }

    @Override
    public Observable<DefaultEvent> publish(DefaultEvent... subjects) {
        if(subjects == null || subjects.length == 0){
            throw new NullPointerException("传入的对象subjects不可以为空！");
        }
        return Observable.from(subjects).subscribeOn(Schedulers.io())/*.observeOn(Schedulers.newThread())*/;
    }

    @Override
    public Observable<DefaultEvent> publish(List<DefaultEvent> subjects) {
        if(subjects == null || subjects.size() == 0){
            throw new NullPointerException("传入的对象subjects不可以为空！");
        }
        return Observable.from(subjects).subscribeOn(Schedulers.io()).observeOn(Schedulers.newThread());
    }

    /**
     * 创建任意对象的事件发布操作
     * @param param
     * @return
     */
    public Observable<?> bind(Object param){
        Optional.of(param);
        return Observable.just(param).subscribeOn(Schedulers.io()).observeOn(Schedulers.newThread());
    }

    /**
     * 创建任意对象的事件
     * @param param
     * @return
     */
    public Observable<?> bind(Object... param){
        Optional.of(param);
        return Observable.just(param).subscribeOn(Schedulers.io()).observeOn(Schedulers.newThread());
    }

    /**
     * 创建任意对象的事件
     * @param param
     * @return
     */
    public Observable<?> bind(List<?> param){
        Optional.of(param);
        return Observable.just(param).subscribeOn(Schedulers.io()).observeOn(Schedulers.newThread());
    }

}
